<?php
error_reporting ( 'E_ALL & ~E_NOTICE' );
class clsShared {
	public static function converterData($string, $tipo = '/') {
		if ($string != '')
			switch ($tipo) {
				case '/' :
					$valor = explode ( '/', $string );
					return $valor [2] . '-' . $valor [1] . '-' . $valor [0];
					break;
			}
	}
	public static function executarSQL($arquivo, $printar = true) {
		$nome_do_arquivo = "$arquivo";
		$arquivo = Array ();
		
		$arquivo = file ( $nome_do_arquivo );
		
		$prepara = "";
		
		foreach ( $arquivo as $v )
			$prepara .= $v;
		$sql = explode ( ";", $prepara );
		foreach ( $sql as $v ) {
			if ($printar)
				echo $v . ';<br />';
			connectorFactory::query ( utf8_decode ( $v ) );
		}
	}
	public static function componentes($caminho) {
		if ($caminho != '')
			$caminho = $caminho . '/';
		echo "
<link href=\"" . $caminho . "css/calendario.css\" rel=\"stylesheet\" type=\"text/css\">
<link href=\"" . $caminho . "css/jHtmlArea.css\" rel=\"stylesheet\" type=\"text/css\">
<link href=\"" . $caminho . "css/colorpicker.css\" rel=\"stylesheet\" type=\"text/css\">
<link href=\"" . $caminho . "css/menu.css\" rel=\"stylesheet\" type=\"text/css\">

<script type=\"text/javascript\" src=\"" . $caminho . "js/html5.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/jquery.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/form.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/shortcut.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/mascara.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/calendario.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/autocomplete.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/reais.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/jHtmlArea.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/colorpicker.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "ckeditor/ckeditor.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "ckeditor/adapters/jquery.js\"></script>
<script type=\"text/javascript\" src=\"" . $caminho . "js/custom.js\"></script>
	";
		echo "\n";
	}
	public static function onBlur($txt, $acao) {
		echo '<script>
			$(document).ready(function() {
				$("#' . $txt . '").blur(function() {
					' . $acao . '
				})
			});</script>';
	}
	public static function preco($str) {
		$search [] = '.';
		$search [] = ',';
		$search [] = 'R$';
		$replace [] = '';
		$replace [] = '.';
		$search [] = '';
		$str = str_replace ( $search, $replace, $str );
		return $str;
	}
	public static function DTEXC($tbl = "") {
		if ($tbl)
			$tbl = $tbl . '.';
		
		$str .= '( ' . $tbl . 'dtinc = ' . $tbl . 'dtexc or ' . $tbl . 'dtexc="0000-00-00 00:00:00" or ' . $tbl . 'dtexc="0001-01-01 00:00:01" )';
		return $str;
	}
	public static function titulo() {
		if (! $_GET ['id'])
			$titulo = 'Cadastro / ';
		else
			$titulo = 'Editar / ';
		
		return $titulo;
	}
	public static function converterSenha($senha) {
		$senha = hash ( 'whirlpool', $senha );
		$a = strlen ( $senha );
		$par = substr ( $senha, 0, round ( $a / 2 ) );
		$impar = substr ( $senha, round ( $a / 2 ), round ( $a / 2 ) );
		
		// $convertido = $par . ' / ' . $impar;
		
		for($i = 0; $i < $a; $i ++)
			$convertido .= $par [$i] . $impar [$i];
		
		return $convertido;
	}
	public static function escrever($acao, $alerta, $focus = "", $valor = "", $data = array()) {
		if ($acao)
			$data ['acao'] = $acao;
		
		if ($alerta)
			$data ['escrever'] = utf8_encode ( $alerta );
		
		if ($focus)
			$data ['focar'] = $focus;
		
		if ($_POST ['receber'] != '') {
			$data ['receber'] = $_POST ['receber'];
			if ($_POST ['id'] == '') {
				if ($valor)
					$data ['referencia'] = $valor;
			} else if ($_GET ['fechar'] == 'sim') {
				if ($valor)
					$data ['referencia'] = $valor;
			}
		}
		echo json_encode ( $data );
		exit ();
	}
}

?>